package top.cptr.simpleRpc.rpccore;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Tiger_L
 * @version 1.0
 * @description rpc context
 * @date 2024/1/4 16:06
 */
public class RpcContContext {
    private final Map<String, RpcItem> mapping = new HashMap<>();

    public void add(String methodName, RpcItem rpcItem) {
        if (mapping.containsKey(methodName)) {
            throw new RuntimeException(String.format("method name is Existed for %s", methodName));
        }
        mapping.put(methodName, rpcItem);
    }

    public RpcItem getRpcItem(String methodName) {
        RpcItem rpcItem = mapping.get(methodName);
        if (rpcItem == null) {
            throw new RuntimeException(String.format("%s absent", methodName));
        }
        return rpcItem;
    }

}
